package com.sgcc.ln.pmos.e_ln_home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;


import com.sgcc.pmos.nativesdk.R;
import com.sgcc.ln.pmos.common.base.BaseRecyclerAdapter;
import com.sgcc.ln.pmos.common.bean.ChartDataBean;

import me.jessyan.autosize.utils.AutoSizeUtils;

/**
 * 文件名：CurveEditorAdapter
 * 作者：Turbo
 * 时间： 12/29/20 10:35 AM
 * 蚁穴虽小，溃之千里。
 */
public class CurveEditorRVSAdapter extends BaseRecyclerAdapter<ChartDataBean> {

    private Context mContext;
    private int mStepSpace;

    public CurveEditorRVSAdapter(Context context, int stepSpace) {
        mContext = context;
        mStepSpace = stepSpace;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.periodtime_horizontal_list_s_item, parent, false);
        return new CurveEditorRVHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int position, ChartDataBean data) {
        CurveEditorRVHolder holder = (CurveEditorRVHolder) viewHolder;
        if (data.isMe()) {
            holder.mTvContent.setText(data.getValue() == -999 ? "--" : data.getValue() + "");
        } else {
            holder.mTvContent.setText(data.getPriceValue() + "");
        }

        RecyclerView.LayoutParams linearParams = (RecyclerView.LayoutParams) holder.mLlContent.getLayoutParams();
        if (position == 0) {
            linearParams.setMargins(-(mStepSpace / 2) + AutoSizeUtils.dp2px(mContext, 100), 0, 0, 0);
        } else {
            linearParams.setMargins(0, 0, 0, 0);
        }
        linearParams.width = mStepSpace;
        holder.mLlContent.setLayoutParams(linearParams);

        if (position == mDatas.size() - 1) {
            holder.mViewLine.setVisibility(View.GONE);
        } else {
            holder.mViewLine.setVisibility(View.VISIBLE);
        }
    }

    class CurveEditorRVHolder extends RecyclerView.ViewHolder {

        public CurveEditorRVHolder(View itemView) {
            super(itemView);
            mLlContent = (RelativeLayout) itemView.findViewById(R.id.ll_content);
            mTvContent = (TextView) itemView.findViewById(R.id.tv_content);
            mViewLine = (View) itemView.findViewById(R.id.view_line);
        }

        private RelativeLayout mLlContent;
        private TextView mTvContent;
        private View mViewLine;



    }
}
